package sat.component;

import java.io.File;

import org.mt4j.MTApplication;
import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;

public class KeyboardTabArrayImage extends MTRectangle{
	
	private MTApplication app;
	private Keyboard keyboard;
	private static int tabNb = 6;
	
	static final float tabListWidth = 640;	//width of keyboard and tabList
	static final float tabListHeight = 25;	//height of tabList

	public void addChildLinearAlign(KeyboardTabImage cmp){ // add a tab in line
		float n = this.getChildCount();
		if(n != 0){
			cmp.setPositionRelativeToParent(new Vector3D(
					tabListWidth/tabNb*(0.5f+n),
					cmp.getPosition(TransformSpace.RELATIVE_TO_PARENT).y
					));
		}
		this.addChild(cmp);
	}
	
	public void allInLine(){
		for (int i = 0; i < this.getChildCount(); i++) {
			KeyboardTabImage temp = (KeyboardTabImage) this.getChildByIndex(i);
			temp.inLine();
		}
	}
	
	public KeyboardTabArrayImage(MTApplication mtApplication,Keyboard kb,int mode) {
		super(mtApplication, 0, 0, 0, tabListWidth, tabListHeight);
		this.app = mtApplication;
		this.keyboard = kb;
		this.setFillColor(MTColor.GRAY);
		this.setStrokeColor(MTColor.BLACK);
		this.unregisterAllInputProcessors(); //Remove the default drag, rotate and scale gestures first
		String imagePath = System.getProperty("user.dir") + File.separator + "icons" + File.separator;
		
		// for case of class diagram
		if(mode==2)
		{
		KeyboardTabImage tab1 = new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"association.JPG");
		KeyboardTabImage tab2=	new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"aggregation.JPG");
		KeyboardTabImage tab3=	new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"heritage.JPG");
		KeyboardTabImage tab4=  new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"composition.JPG");
		KeyboardTabImage tab5=  new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"dependency.JPG");
		KeyboardTabImage tab6=  new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"realization.JPG");
		
		this.addChildLinearAlign(tab1);
		this.addChildLinearAlign(tab2);
		this.addChildLinearAlign(tab3);
		this.addChildLinearAlign(tab4);
		this.addChildLinearAlign(tab5);
		this.addChildLinearAlign(tab6);
		}
		
		//for case of use case diagram
		if(mode==3)
		{	
			KeyboardTabArrayImage.tabNb=5;
			
			KeyboardTabImage tab1 = new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"user.JPG");
			KeyboardTabImage tab2=	new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"usecase.JPG");
			KeyboardTabImage tab3=	new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"inclusion.JPG");
			KeyboardTabImage tab4=  new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"extension.JPG");
			KeyboardTabImage tab5=  new KeyboardTabImage(app,keyboard,tabListWidth/tabNb,tabListHeight-1,imagePath+"generation.JPG");
			
			this.addChildLinearAlign(tab1);
			this.addChildLinearAlign(tab2);
			this.addChildLinearAlign(tab3);
			this.addChildLinearAlign(tab4);
			this.addChildLinearAlign(tab5);
		}
		
	}

}
